<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增分类</title>

    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <script type="text/javascript" th:src="@{/static/js/jquery-3.js}"></script>
    <script th:src="@{/static/layui/layui.js}" charset="utf-8"></script>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>增加分类</legend>
</fieldset>

<div class="layui-form-item">
    <label class="layui-form-label">分类名称&nbsp;:</label>
    <div class="layui-input-block">
        <input type="text" name='name' id="name" lay-verify="required" lay-reqtext="分类名称为必填" placeholder="请输分类名称" autocomplete="off"  style="width:500px;"   class="layui-input" >
    </div>
</div>

<div class="layui-form-item">
    <div class="layui-input-block">
        <button type="submit" class="layui-btn" lay-submit="" lay-filter="subBtn">新增</button>
    </div>
</div>

<script>

    var basePath="/";

    layui.use(['form'],function () {
        var thisIndex = parent.layer.getFrameIndex(window.name);
        var form = layui.form;
        var parentLayer = parent.layer;
        form.on("submit(subBtn)",function () {
            var name = $("#name").val();
            if(name == null || name === ""){
                layer.msg("请输入分类名称");
                return ;
            }
            var obj = {
                name: name,
            };
            console.log(obj);
            $.post(basePath+"classify/add",obj,function (data) {
                if(data.code == 9999){
                    parentLayer.msg("添加失败，该用户已经存在",{
                        icon: 1,
                        time: 10000
                    });
                }else{
                    parentLayer.msg("添加成功",{
                        icon: 1,
                        time: 20000
                    });
                }
                window.parent.location.reload();
                parentLayer.close(thisIndex);
            },"json");

        })
    })

</script>

</body>
</html>